package com.example.xyxwebbackend001.controller;

import com.example.xyxwebbackend001.common.CommonResult;
import com.example.xyxwebbackend001.model.DTO.ArticleSimpleDTO;
import com.example.xyxwebbackend001.model.entity.HomeImagesData;
import com.example.xyxwebbackend001.service.FileStorageService;
import com.example.xyxwebbackend001.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @Autowired
    private FileStorageService fileStorageService;
    @GetMapping("/carousel")
    public CommonResult<List<HomeImagesData>> getCarousel(@RequestParam(value = "title", required = false)
                                                           String title) {
        return CommonResult.success(homeService.getCarouselList(title));
    }

    @GetMapping("/hot-rec/articles")
    public CommonResult<List<ArticleSimpleDTO>> getArticlesByViews() {
        return CommonResult.success(homeService.getArticleListByViews(null));
    }

    @GetMapping("latest-rec/articles")
    public CommonResult<List<ArticleSimpleDTO>> getLatestArticles() {
        return CommonResult.success(homeService.getArticleListByViews("create_time DESC"));
    }
}
